using System;
using EPiServer.Common;
using EPiServer.Common.Queries;
using EPiServer.Community.Forum;
using EPiServer.Community.Forum.Queries;

namespace EPiAbstractions.Community.Forum
{
    public class ForumHandlerFacade : IForumHandlerFacade
    {
        private static ForumHandlerFacade _instance;

        public ForumHandlerFacade()
        {
            ForumHandler.ForumAdded += OnForumAdded;
            ForumHandler.ForumUpdated += OnForumUpdated;
            ForumHandler.ForumRemoved += OnForumRemoved;
            ForumHandler.IconAdded += OnIconAdded;
            ForumHandler.IconUpdated += OnIconUpdated;
            ForumHandler.IconRemoved += OnIconRemoved;
            ForumHandler.ReplyAdded += OnReplyAdded;
            ForumHandler.ReplyUpdated += OnReplyUpdated;
            ForumHandler.ReplyRemoved += OnReplyRemoved;
            ForumHandler.RoomAdded += OnRoomAdded;
            ForumHandler.RoomUpdated += OnRoomUpdated;
            ForumHandler.RoomRemoved += OnRoomRemoved;
            ForumHandler.StyleSheetAdded += OnStyleSheetAdded;
            ForumHandler.StyleSheetUpdated += OnStyleSheetUpdated;
            ForumHandler.StyleSheetRemoved += OnStyleSheetRemoved;
            ForumHandler.TopicAdded += OnTopicAdded;
            ForumHandler.TopicUpdated += OnTopicUpdated;
            ForumHandler.TopicRemoved += OnTopicRemoved;
            ForumHandler.TopicMoved += OnTopicMoved;
        }

        public static ForumHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new ForumHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IForumHandlerFacade Members

        public event EPiServerCommonEventHandler ForumAdded;
        public event EPiServerCommonEventHandler ForumUpdated;
        public event EPiServerCommonEventHandler ForumRemoved;
        public event EPiServerCommonEventHandler IconAdded;
        public event EPiServerCommonEventHandler IconUpdated;
        public event EPiServerCommonEventHandler IconRemoved;
        public event EPiServerCommonEventHandler ReplyAdded;
        public event EPiServerCommonEventHandler ReplyUpdated;
        public event EPiServerCommonEventHandler ReplyRemoved;
        public event EPiServerCommonEventHandler RoomAdded;
        public event EPiServerCommonEventHandler RoomUpdated;
        public event EPiServerCommonEventHandler RoomRemoved;
        public event EPiServerCommonEventHandler StyleSheetAdded;
        public event EPiServerCommonEventHandler StyleSheetUpdated;
        public event EPiServerCommonEventHandler StyleSheetRemoved;
        public event EPiServerCommonEventHandler TopicAdded;
        public event EPiServerCommonEventHandler TopicUpdated;
        public event EPiServerCommonEventHandler TopicRemoved;
        public event EPiServerCommonEventHandler TopicMoved;

        public virtual EPiServer.Community.Forum.Forum AddForum(EPiServer.Community.Forum.Forum forum)
        {
            return ForumHandler.AddForum(forum);
        }

        public virtual void UpdateForum(EPiServer.Community.Forum.Forum forum)
        {
            ForumHandler.UpdateForum(forum);
        }

        public virtual void RemoveForum(EPiServer.Community.Forum.Forum forum)
        {
            ForumHandler.RemoveForum(forum);
        }

        public virtual EPiServer.Community.Forum.Forum GetForum(Int32 forumId)
        {
            return ForumHandler.GetForum(forumId);
        }

        public virtual ForumCollection GetForums()
        {
            return ForumHandler.GetForums();
        }

        public virtual ForumCollection GetForums(SiteCollection sites)
        {
            return ForumHandler.GetForums(sites);
        }

        public virtual ForumCollection GetForums(SiteCollection sites, NullValueAction siteNullAction)
        {
            return ForumHandler.GetForums(sites, siteNullAction);
        }

        public virtual StyleSheet AddStyleSheet(StyleSheet styleSheet)
        {
            return ForumHandler.AddStyleSheet(styleSheet);
        }

        public virtual void UpdateStyleSheet(StyleSheet styleSheet)
        {
            ForumHandler.UpdateStyleSheet(styleSheet);
        }

        public virtual void RemoveStyleSheet(StyleSheet styleSheet)
        {
            ForumHandler.RemoveStyleSheet(styleSheet);
        }

        public virtual StyleSheet GetStyleSheet(Int32 styleSheetId)
        {
            return ForumHandler.GetStyleSheet(styleSheetId);
        }

        public virtual StyleSheetCollection GetStyleSheets()
        {
            return ForumHandler.GetStyleSheets();
        }

        public virtual Icon AddIcon(Icon icon)
        {
            return ForumHandler.AddIcon(icon);
        }

        public virtual void UpdateIcon(Icon icon)
        {
            ForumHandler.UpdateIcon(icon);
        }

        public virtual void RemoveIcon(Icon icon)
        {
            ForumHandler.RemoveIcon(icon);
        }

        public virtual Icon GetIcon(Int32 iconId)
        {
            return ForumHandler.GetIcon(iconId);
        }

        public virtual IconCollection GetIcons()
        {
            return ForumHandler.GetIcons();
        }

        public virtual Reply AddReply(Reply reply)
        {
            return ForumHandler.AddReply(reply);
        }

        public virtual void UpdateReply(Reply reply)
        {
            ForumHandler.UpdateReply(reply);
        }

        public virtual void RemoveReply(Reply reply)
        {
            ForumHandler.RemoveReply(reply);
        }

        public virtual Reply GetReply(Int32 replyId)
        {
            return ForumHandler.GetReply(replyId);
        }

        public virtual MessageCollection GetReplies(Topic topic, Int32 page, Int32 pageSize, ReplySortOrder[] order)
        {
            return ForumHandler.GetReplies(topic, page, pageSize, order);
        }

        public virtual MessageCollection GetReplies(Topic topic, Int32 page, Int32 pageSize, out Int32 totalItems, ReplySortOrder[] order)
        {
            return ForumHandler.GetReplies(topic, page, pageSize, out totalItems, order);
        }

        public virtual Int32 GetListingPageNumber(Reply reply, Int32 pageSize, ReplySortOrder[] sortOrder)
        {
            return ForumHandler.GetListingPageNumber(reply, pageSize, sortOrder);
        }

        public virtual ChildRoom ConvertToChildRoom(Room room, RoomBase parentRoom)
        {
            return ForumHandler.ConvertToChildRoom(room, parentRoom);
        }

        public virtual Room ConvertToRootRoom(ChildRoom room, EPiServer.Community.Forum.Forum forum)
        {
            return ForumHandler.ConvertToRootRoom(room, forum);
        }

        public virtual RoomBase AddRoom(RoomBase room)
        {
            return ForumHandler.AddRoom(room);
        }

        public virtual void UpdateRoom(RoomBase room)
        {
            ForumHandler.UpdateRoom(room);
        }

        public virtual void RemoveRoom(RoomBase room)
        {
            ForumHandler.RemoveRoom(room);
        }

        public virtual RoomBase GetRoom(Int32 roomId)
        {
            return ForumHandler.GetRoom(roomId);
        }

        public virtual RoomBase GetPreviousRoom(RoomBase currentRoom)
        {
            return ForumHandler.GetPreviousRoom(currentRoom);
        }

        public virtual RoomBase GetNextRoom(RoomBase currentRoom)
        {
            return ForumHandler.GetNextRoom(currentRoom);
        }

        public virtual RoomCollection GetRooms(EPiServer.Community.Forum.Forum forum)
        {
            return ForumHandler.GetRooms(forum);
        }

        public virtual RoomCollection GetRooms(RoomBase parentRoom)
        {
            return ForumHandler.GetRooms(parentRoom);
        }

        public virtual Topic AddTopic(Topic topic)
        {
            return ForumHandler.AddTopic(topic);
        }

        public virtual void UpdateTopic(Topic topic)
        {
            ForumHandler.UpdateTopic(topic);
        }

        public virtual void IncrementViews(Topic topic)
        {
            ForumHandler.IncrementViews(topic);
        }

        public virtual Topic MoveTopic(Topic topic, RoomBase toRoom, TopicTrace trace)
        {
            return ForumHandler.MoveTopic(topic, toRoom, trace);
        }

        public virtual void RemoveTopic(Topic topic)
        {
            ForumHandler.RemoveTopic(topic);
        }

        public virtual Topic GetTopic(Int32 topicId)
        {
            return ForumHandler.GetTopic(topicId);
        }

        public virtual MessageCollection GetTopics(Int32 page, Int32 pageSize, TopicSortOrder[] order)
        {
            return ForumHandler.GetTopics(page, pageSize, order);
        }

        public virtual MessageCollection GetTopics(Int32 page, Int32 pageSize, out Int32 totalItems, TopicSortOrder[] order)
        {
            return ForumHandler.GetTopics(page, pageSize, out totalItems, order);
        }

        public virtual MessageCollection GetTopics(RoomCollection rooms, Int32 page, Int32 pageSize, TopicSortOrder[] order)
        {
            return ForumHandler.GetTopics(rooms, page, pageSize, order);
        }

        public virtual MessageCollection GetTopics(RoomCollection rooms, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                   TopicSortOrder[] order)
        {
            return ForumHandler.GetTopics(rooms, page, pageSize, out totalItems, order);
        }

        public virtual Int32 GetListingPageNumber(Topic topic, Int32 pageSize, TopicSortOrder[] sortOrder)
        {
            return ForumHandler.GetListingPageNumber(topic, pageSize, sortOrder);
        }

        public virtual Int32 GetListingPageNumber(RoomCollection rooms, Topic topic, Int32 pageSize, TopicSortOrder[] sortOrder)
        {
            return ForumHandler.GetListingPageNumber(rooms, topic, pageSize, sortOrder);
        }

        public virtual ForumCollection GetQueryResult(ForumQuery query)
        {
            return ForumHandler.GetQueryResult(query);
        }

        public virtual ForumCollection GetQueryResult(ForumQuery query, Int32 page, Int32 pageSize)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual ForumCollection GetQueryResult(ForumQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual RoomCollection GetQueryResult(RoomQuery query)
        {
            return ForumHandler.GetQueryResult(query);
        }

        public virtual RoomCollection GetQueryResult(RoomQuery query, Int32 page, Int32 pageSize)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual RoomCollection GetQueryResult(RoomQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual MessageCollection GetQueryResult(TopicQuery query)
        {
            return ForumHandler.GetQueryResult(query);
        }

        public virtual MessageCollection GetQueryResult(TopicQuery query, Int32 page, Int32 pageSize)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual MessageCollection GetQueryResult(TopicQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual MessageCollection GetQueryResult(ReplyQuery query)
        {
            return ForumHandler.GetQueryResult(query);
        }

        public virtual MessageCollection GetQueryResult(ReplyQuery query, Int32 page, Int32 pageSize)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual MessageCollection GetQueryResult(ReplyQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return ForumHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        #endregion

        public virtual void OnForumAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ForumAdded != null)
                ForumAdded(sender, e);
        }

        public virtual void OnForumUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (ForumUpdated != null)
                ForumUpdated(sender, e);
        }

        public virtual void OnForumRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (ForumRemoved != null)
                ForumRemoved(sender, e);
        }

        public virtual void OnIconAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (IconAdded != null)
                IconAdded(sender, e);
        }

        public virtual void OnIconUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (IconUpdated != null)
                IconUpdated(sender, e);
        }

        public virtual void OnIconRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (IconRemoved != null)
                IconRemoved(sender, e);
        }

        public virtual void OnReplyAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (ReplyAdded != null)
                ReplyAdded(sender, e);
        }

        public virtual void OnReplyUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (ReplyUpdated != null)
                ReplyUpdated(sender, e);
        }

        public virtual void OnReplyRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (ReplyRemoved != null)
                ReplyRemoved(sender, e);
        }

        public virtual void OnRoomAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (RoomAdded != null)
                RoomAdded(sender, e);
        }

        public virtual void OnRoomUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (RoomUpdated != null)
                RoomUpdated(sender, e);
        }

        public virtual void OnRoomRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (RoomRemoved != null)
                RoomRemoved(sender, e);
        }

        public virtual void OnStyleSheetAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (StyleSheetAdded != null)
                StyleSheetAdded(sender, e);
        }

        public virtual void OnStyleSheetUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (StyleSheetUpdated != null)
                StyleSheetUpdated(sender, e);
        }

        public virtual void OnStyleSheetRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (StyleSheetRemoved != null)
                StyleSheetRemoved(sender, e);
        }

        public virtual void OnTopicAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (TopicAdded != null)
                TopicAdded(sender, e);
        }

        public virtual void OnTopicUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (TopicUpdated != null)
                TopicUpdated(sender, e);
        }

        public virtual void OnTopicRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (TopicRemoved != null)
                TopicRemoved(sender, e);
        }

        public virtual void OnTopicMoved(String sender, EPiServerCommonEventArgs e)
        {
            if (TopicMoved != null)
                TopicMoved(sender, e);
        }
    }
}